import tkinter as tk
 
# 创建主窗口
root = tk.Tk()
root.title("第一个 Tkinter 窗口")  # 设置窗口标题
root.geometry("400x300")         # 设置窗口大小（宽 x 高）
 
# 运行主循环
root.mainloop()


import tkinter as tk
 
root = tk.Tk()
root.title("Label 示例")
 
# 创建一个 Label
label = tk.Label(root, text="Hello, Tkinter!", font=("Arial", 16), fg="blue")
label.pack(pady=20)  # 显示控件，并设置上下间距
 
root.mainloop()


import tkinter as tk
 
def on_click():
    print("按钮被点击了！")
 
root = tk.Tk()
root.title("Button 示例")
 
# 创建按钮
button = tk.Button(root, text="点击我", command=on_click, font=("Arial", 14))
button.pack(pady=20)
 
root.mainloop()



import tkinter as tk
 
def show_text():
    print(f"输入的内容：{entry.get()}")  # 获取输入内容
 
root = tk.Tk()
root.title("Entry 示例")
 
# 创建输入框
entry = tk.Entry(root, font=("Arial", 14))
entry.pack(pady=10)
 
# 创建按钮
button = tk.Button(root, text="提交", command=show_text)
button.pack(pady=10)
 
root.mainloop()


import tkinter as tk
 
def show_text():
    print(f"输入的内容：\n{text.get('1.0', tk.END)}")  # 获取多行内容
 
root = tk.Tk()
root.title("Text 示例")
 
# 创建多行文本框
text = tk.Text(root, height=5, width=40, font=("Arial", 14))
text.pack(pady=10)
 
# 创建按钮
button = tk.Button(root, text="提交", command=show_text)
button.pack(pady=10)
 
root.mainloop()



import tkinter as tk
 
def show_selection():
    print(f"选项 1：{'选中' if var1.get() else '未选中'}")
    print(f"选项 2：{'选中' if var2.get() else '未选中'}")
 
root = tk.Tk()
root.title("Checkbutton 示例")
 
# 创建变量
var1 = tk.IntVar()
var2 = tk.IntVar()
 
# 创建复选框
check1 = tk.Checkbutton(root, text="选项 1", variable=var1)
check1.pack()
check2 = tk.Checkbutton(root, text="选项 2", variable=var2)
check2.pack()
 
# 创建按钮
button = tk.Button(root, text="提交", command=show_selection)
button.pack(pady=10)
 
root.mainloop()